<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no" />
    <title>推荐</title>
    <link rel="stylesheet" href="../../css/api.css">
    <link rel="stylesheet" href="../../css/vant.css">
    <link rel="stylesheet" href="../../css/main.css">
    <style>
        header {
            height: auto;
        }

        .my_tab_props {
            /* width: auto;
            margin-right: 15px;
            color: black; */
            border: 1px solid black;
        }

        .van-tab {
            flex: none;
        }

        .van-tabs__wrap--scrollable .van-tab {
            flex: none;
            padding: 0 10px;
        }
    </style>
</head>

<body>
    <div class="app" v-cloak>
        <van-tabs class="my_tab_head" v-model="active" color="#ffffff" title-inactive-color="#666666"
            title-active-color="#2A2A2A" @click="setFrameGroupIndex" scrollspy sticky>
            <van-tab v-for="item in categoryList" :title="item.val">
            </van-tab>
        </van-tabs>
    </div>
    <script src="../../script/api.js"></script>
    <script src="../../script/flexible.js"></script>
    <script src="../../script/fastclick.js"></script>
    <script src="../../script/vue.min.js"></script>
    <script src="../../script/iconfont.js"></script>
    <script src="../../script/vant.min.js"></script>
    <script src="../../script/swiper.min.js"></script>
    <script src="../../script/common.js"></script>
    <script src="../../script/businessCommon.js"></script>
    <script src="../../script/restful.js"></script>
    <script>
        apiready = function () {
            vm = new Vue({
                el: '.app',
                data: {
                    headerH: 0,
                    footerH: 0,
                    frames: [],
                    active: 0,
                    categoryList: [],
                    selectActive: 0
                },
                mounted() {
                    this.footerH = api.pageParam.footerH;
                    var header = $api.dom('.my_tab_head');
                    this.headerH = $api.offset(header).h;
                    if (this.categoryList.length == 0) {
                        this.getCategoryList()
                    }
                },

                methods: {
                    //获取分类频道
                    getCategoryList() {
                        var vm = this
                        release("getListOptions")(10, function (ret, err) {
                            if (ret.data && ret.data.length > 0) {

                                vm.categoryList = ret.data
                                vm.categoryList.unshift({ val: "推荐", id: null })//增加全部分类

                                vm.frames = []
                                vm.categoryList.forEach(item => {
                                    var framItem = {
                                        name: 'circle_list_frm',
                                        url: './circle_list_frm.html',
                                        pageParam: {
                                            screenType: 0,
                                            channelId: item.id
                                        }
                                    }
                                    vm.frames.push(framItem)
                                });
                                vm.$nextTick(() => {
                                    // 更改列表之间的间距
                                    $api.domAll('.van-tab').forEach(item => {
                                        $api.css(item, 'flex-basis: auto;')
                                    })
                                })
                                vm.openFrameGroup();
                            }
                        });
                    },
                    openFrameGroup() {
                        var vm = this;
                        api.openFrameGroup({
                            name: 'circle_recommend_group',
                            rect: {
                                marginTop: vm.headerH + api.pageParam.headH,
                                marginBottom: vm.footerH,

                            },
                            scrollEnabled: true,
                            frames: vm.frames,
                            preload: 3,
                        }, function (ret, err) {
                            vm.active = ret.index;
                            api.sendEvent({
                                name: 'eventTab',
                                extra: { key: ' value' }
                            });
                        });
                    },
                    setFrameGroupIndex() {
                        api.setFrameGroupIndex({
                            name: 'circle_recommend_group',
                            scroll: true,
                            index: this.active,
                            reload: true
                        });
                    },
                },
            })
        }
    </script>
</body>

</html>